package service;

import gui.MD5;

import java.util.Vector;

import model.Account;

import dao.IDao_LogIn;

public class ServiceImp_LogIn implements IService_LogIn
{
	private IDao_LogIn dao_LogIn;

	public ServiceImp_LogIn(IDao_LogIn dao_LogIn)
	{
		this.dao_LogIn=dao_LogIn;
	}


	public boolean login(Account account)
	{
		Vector<Vector<Object>> vector = dao_LogIn.login(account);
		if (vector.isEmpty())
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	public int modifyPassword(Account account,String newPwd,String repNewPwd)
	{
		if (newPwd.length() < 6 || newPwd.length() > 14)
		{
			return -1;
		}
		else
		{
			if (!newPwd.equals(repNewPwd))
			{
				return -2;
			}
			else
			{
				boolean check = login(account);
				if (check)
				{
					dao_LogIn.modifyPassword(account,MD5.Md5(newPwd));
					return 1;
				}
				else
				{
					return -3;
				}
			}
		}
	}

}
